# -*- coding: utf-8 -*-
"""
@Time    : 2024/9/12 16:08 
@Author  : ZhangShenao 
@File    : service.py
@Desc    : 用户Service
"""
from injector import inject

from dao import UserDao
from entity import UserEntity


class UserService:
    """用户Service"""

    @inject  # 通过inject装饰器实现依赖注入,自动注入UserDao对象
    def __init__(self, dao: UserDao):
        """
        构造函数
        :param dao: UserDao对象,通过依赖注入
        """

        # 初始化
        self.dao = dao

    def get_by_id(self, user_id: int) -> UserEntity:
        """
        根据user_id查询用户
        :param user_id: 用户ID
        :return: 用户实体对象
        """

        # 调用dao实现
        return self.dao.select_by_id(user_id)
